package jdbc;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class SelectResultSet {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url = "jdbc:mysql://localhost:3306/java75?useSSL=false&useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true&allowMultiQueries=true";
        Connection con = null;
        PreparedStatement ps =null;
        ResultSet rs=null;
        try {
            con = DriverManager.getConnection(url, "root", "root1234");
            ps=con.prepareStatement("select * from s_student order by stuno desc",ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            rs=ps.executeQuery();
            rs.next();
            rs.next();
            rs.next();
            System.out.println(rs.getLong("stuno")+",姓名："+rs.getString("sname"));
            rs.absolute(100);
            rs.previous();
            rs.previous();
            System.out.println(rs.getLong("stuno")+",姓名："+rs.getString("sname"));
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                if (ps != null)
                    ps.close();

            } catch (Exception e) {
                e.printStackTrace();
            }
            try {

                if (con != null)
                    con.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
